package com.zhiyou100.api.collections_demo;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Demo1 {

    public static void main(String[] args) {
        test();
    }


    //排序
    public static void test(){
        List<Integer> list = Arrays.asList(12,45,78,98,65,21,32);
        //升序排序
        Collections.sort(list);
        System.out.println("升序后的结果 = " + list);
        //自定义排序规则
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        System.out.println("降序：" + list);

        Collections.reverse(list);
        System.out.println("逆向排序" + list);

        Collections.shuffle(list);
        System.out.println("随机排序：" + list);
        //模拟扑克牌发牌过程   54张
        Collections.swap(list,2,5);
        System.out.println("交换元素后：" + list);

        Collections.rotate(list,-3);
        System.out.println("前移、后移后：" + list);

    }


}
